<?php
	
	// ** Logout the current user. **
	$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
	if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
	  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
	}
	
	if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
	  //to fully log out a visitor we need to clear the session varialbles
	  $_SESSION['MM_Username'] = NULL;
	  $_SESSION['MM_UserGroup'] = NULL;
	  $_SESSION['PrevUrl'] = NULL;
	  unset($_SESSION['MM_Username']);
	  unset($_SESSION['MM_UserGroup']);
	  unset($_SESSION['PrevUrl']);
		
	  $logoutGoTo = "logout.php";
	  if ($logoutGoTo) {
		header("Location: $logoutGoTo");
		exit;
	  }
	}
?>

<div id="barra-fixa">    

    <div id="sticky_navigation">
	    <div id="linha-fixa"></div>
    
        <div class="demo_container">
        
        <a href="/bagulho/?pg=principal"><div id="logo">
            <p class="txt-logo">Bagulho Louco</p>
            <p class="txt-legenda">Aqui o bagulho é louco!</p>
        </div></a>
        
        
        <div id="barra-itens">
        <?php if (($_GET['pg'] == 'principal') || ($_GET['pg'] == 'lidas') || ($_GET['pg'] == 'comentadas') || ($_GET['pg'] == 'recentes') || ($_GET['pg'] == '')) { ?>
            <ul>
                <li class="top-link"><a href="?pg=lidas">Mais Lidas</a></li>
                <li class="top-link"><a href="?pg=comentadas">Mais Comentadas</a></li>
                <li class="top-link"><a href="?pg=recentes">Recentes</a></li>
            </ul>
        <?php } else { } ?>

        </div>
        
        <div id="barra-user">
        <?php if (isset($_SESSION["autenticado"]) == true) { ?>
        <div class="txt-user">
            <div class="dropdown">
                <a class="account" ><?php echo $_SESSION['nome']; ?></a>
                
                <div class="submenu">
                    <ul class="root">
                    <li ><a href="?pg=perfil">Meu Perfil</a></li>
                    <li ><a href="?pg=acesso">Dados de Acesso</a></li>
                    <li ><a href="?pg=inbox">Minhas Notícias</a></li>
                    <li ><a href="<?php echo $logoutAction ?>">Sair</a></li>
                    </ul>
                </div>            
            </div>
        </div>                
        <?php } else { ?>
            <a href="?pg=login"><div class="txt-user">Entrar no Bagulho</div></a>
        <?php } ?>

            <div class="txt-sociais">
                <div id="sociais1" class="sociais" title="@bagulholouco"><img src="files/images/icon_social_twitter.png" width="22" height="22" /></div>
                <div id="sociais2" class="sociais" title="facebook.com/bagulho"><img src="files/images/icon_social_facebook.png" width="22" height="22" /></div>
                <div id="sociais3" class="sociais" title="googleplus.com/bagulho"><img src="files/images/icon_social_google.png" width="22" height="22" /></div>
            </div>
        </div>
        
        </div>
    </div>
</div>
    
    
<script type="text/javascript" >
    $(document).ready(function() {    
	    $(".account").click(function() {
			var X=$(this).attr('id');
			if(X==1) {
				$(".submenu").hide();
				$(this).attr('id', '0'); 
			} else {
				$(".submenu").show();
				$(this).attr('id', '1');
			}
			
			});
			
			//Mouse click on sub menu
			$(".submenu").mouseup(function() {
				return false
			});
			
			//Mouse click on my account link
			$(".account").mouseup(function() {
			return false
		});
    
    
    //Document Click
    $(document).mouseup(function() {
   	 	$(".submenu").hide();
    	$(".account").attr('id', '');
    });
    });
</script>